<!-- , `${props.index}-${item.meta.id}` -->
<template>
  <template v-for="item in props.menuData" :key="item.id">
    <el-menu-item
      @click="handleClick(item, `${props.index}-${item.meta.id}`)"
      v-if="!item.children"
      :index="`${props.index}-${item.meta.id}`"
      :key="`${props.index}-${item.meta.id}`"
    >
      <el-icon size="20">
        <!-- .动态组件 -->
        <component :is="item.meta.icon"></component>
      </el-icon>
      <span>{{ $t(`messages.${item.meta.title}`) }}</span>
    </el-menu-item>
    <el-sub-menu v-else :index="`${props.index}-${item.meta.id}`">
      <template #title>
        <el-icon size="20">
          <!-- .动态组件 -->
          <component :is="item.meta.icon"></component>
        </el-icon>
        <span>{{ $t(`messages.${item.meta.title}`) }}</span>
      </template>
      <!-- .递归 -->
      <tree-menu
        :index="`${props.index}-${item.meta.id}`"
        :menuData="item.children"
      />
    </el-sub-menu>
  </template>
</template>

<script setup>
import { useRouter } from "vue-router";
import { headStore } from "@/stores/headStore.js";
const headData = headStore();
const router = useRouter();
const props = defineProps(["menuData", "index"]);
// console.log("🚀 ~ props:", props.menuData);
// 点击菜单
const handleClick = (item) => {
  headData.addMenuAction(item.meta);
  router.push(item.meta.path);
};
</script>

<style></style>
